using System;
using System.Collections.Generic;
using System.Text;
using ACS.Compiler.Parser;
using ACS.Compiler.Tables;
using antlr;
using antlr.collections;

namespace ACS.Compiler.Tree.Impl
{
    public class Module : TreeBase
    {
        private List<TypeDef> _types = new List<TypeDef>();
        private Data _data;
        private List<Proc> _procedures = new List<Proc>();
        private Block _code;
        private List<DataField> _fields = new List<DataField>();

        public List<DataField> Fields
        {
            get { return _fields; }
        }

        public List<TypeDef> Types
        {
             get { return _types; }
        }

        public Data Data
        {
            get { return _data; }
        }

        public override void AllFieldsParsed()
        {
            CodeTable.Instance.AddCodeBase(new CodeBase(this, FileParser.CurrentFileParser.ModuleName));
        }

        public override void MatchBlock(Block block)
        {
            _code = block;
        }

        public override void MatchData(Data data)
        {
            _data = data;
            foreach (TypeField field in data.Fields)
            {
                Fields.Add(DataTable.Instance.AddData(field.Declarer, field.FieldName, FileParser.CurrentFileParser.ModuleName));
            }
        }

        public override void MatchProc(Proc proc)
        {
            _procedures.Add(proc);
        }
            
        public override void MatchType(TypeDef def)
        {
            _types.Add(def); 
        }

        public override string ToString()
        {
            return "Code";
        }

        public List<Proc> Procedures
        {
            get { return _procedures; }
        }

        public Block Code
        {
            get { return _code; }
        }

        public override TreeTags Tag
        {
            get
            {
                return TreeTags.Module;
            }
        }

    }
}
